/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.example;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>Project: javaseapp - Math01
 * <p>Powered by webrx On 2021-07-28 16:45:37
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Math02 {
    public static void main(String[] args) throws ParseException {
        //System.out.println(Math.random());
        //System.out.println(Math.random());
        //System.out.println(Math.random());
        //System.out.println(Math.random());
        //产生0-9 随机数
        for (int i = 1; i <= 20; i++) {
            //0 - 9 随机整数
            int num = (int) Math.round(Math.random() * (9 - 0)) + 0;
            // 0.0000001 * 9   0.000009  0
            // 0.999999924 *9  8.1   8
            System.out.printf("%d ", num);
        }

        //编写程序，输出2021-07-01 0:0:0 到 now 之间的随机Date
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d = sdf.parse("2021-7-1 0:0:0");
        long start = d.getTime();
        long now = System.currentTimeMillis();

        long time = Math.round(Math.random() * (now - start)+ start) ;
        System.out.println(sdf.format(time));

        //随机16进制颜色
        int red = (int)Math.round(Math.random()*255);
        int green = (int)Math.round(Math.random()*255);
        int blue = (int)Math.round(Math.random()*255);
        String color = String.format("#%02x%02x%02x",red,green,blue);
        System.out.println(color);


    }
}
